import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedstate from 'vuex-persistedstate'

//  导入的命名空间
import user from './modules/user'
import musicbook from './modules/musicbook'

Vue.use(Vuex)

Vue.use(Vuex);

const store = new Vuex.Store({
  modules:{
    user,
    musicbook
    
  },
  plugins: [
    createPersistedstate({
      key: 'bookStore', 
      path:['user'],
      storage: window.localStorage, 
    })
  ],
  state: {
    isShowFooter: true,
    bookshelf: [], // 书架状态，初始为空数组
    commentshelf: [],
  },
  mutations: {
    addBookToShelf(state, book) {
      state.bookshelf.push(book); // 将书籍添加到书架状态
    },
    addCommentToShelf(state, comment) {
      state.commentshelf.push(comment); // 将书籍添加到书架状态
    },
    setShowFooter(state, payload) {
      state.isShowFooter = payload;
    },
  },
  actions: {
    addBookToShelf({ commit }, book) {
      commit("addBookToShelf", book); // 提交mutation以添加书籍到书架状态
    },
    addCommentToShelf({ commit }, comment) {
      commit("addCommentToShelf", comment);
    },
  },
});

export default store;
